<template>
  <view class="container">
    <scroll-view scroll-y="true" style="width: 100%; height: 100vh" @scrolltolower="more">
      <view class="list">
        <view class="item" v-for="item in list" :key="item.id" @click="gostudentdetail(item.id)">
          <view class="top">
            <!-- 头像 -->
            <image :src="imgUrl + item.avatar" mode="aspectFill" style="width: 186rpx; height: 186rpx; border-radius: 20rpx"></image>
            <!-- 信息 -->
            <view class="topright">
              <view class="right">
                <view style="font-size: 30rpx; font-family: PingFang SC, PingFang SC; font-weight: bold; color: #222222">{{ item.username }}</view>
                <image :src="`../../static/icon/${item.gender == 1 ? 'nv' : 'nan'}.png`" mode="aspectFill" style="width: 42rpx; height: 42rpx; margin: 0 4rpx"></image>
                <view class="school" v-if="item.school != ''">{{ item.school }}</view>
              </view>
              <view style="font-size: 26rpx; font-family: PingFang SC, PingFang SC; font-weight: 500; color: #222222; margin: 12rpx 0 40rpx 0">
                {{ item.grade_name + '/' + item.subject_name }}
              </view>
              <view style="font-size: 28rpx; font-family: PingFang SC, PingFang SC; font-weight: 500; color: #222222">已授课程{{ item.period_out + '/' + item.period_num }}</view>
            </view>
          </view>
          <!-- 按钮 -->
          <view class="bottom">
            <view class="checkbtn" @click.stop="gocheckgrades(item.user_id)">查看成绩</view>
            <view class="savebtn" @click.stop="gosavework(item.id)" v-if="item.homework == 0">留作业</view>
            <view class="savebtn" @click.stop="gocheckwork(item.id)" v-else>查看作业</view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      page: 1,
      list: [],
      imgUrl: ''
    };
  },
  methods: {
    more() {
      this.page++;
      this.getmystudent();
    },
    // 获取我的学生
    async getmystudent() {
      const res = await uni.$http.post('/teacher_order/student', {
        page: this.page
      });
      console.log('我的学生列表', res.data.data.list);

      if (res.data.data.list.length != 0) {
        this.list.push(...res.data.data.list);
      } else {
        uni.showToast({
          title: '数据已加载完毕',
          icon: 'none'
        });
      }
    },
    // 跳转到查看我的成绩
    gocheckgrades(id) {
      uni.navigateTo({
        url: '/teacher/checkgrades/checkgrades?id=' + id
      });
    },
    // 跳转到留作业
    gosavework(id) {
      uni.navigateTo({
        url: '/teacher/savework/savework?id=' + id
      });
    },
    // 跳转到查看作业
    gocheckwork(id) {
      uni.navigateTo({
        url: '/teacher/checkwork/checkwork?id=' + id
      });
    },
    // 跳转到我的学生详情
    gostudentdetail(id) {
      uni.navigateTo({
        url: '/teacher/studentdetail/studentdetail?id=' + id
      });
    }
  },
  onLoad() {
    this.imgUrl = this.imgurl;
  },
  onShow() {
    this.page = 1;
    this.list = [];
    this.getmystudent();
  }
};
</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  .list {
    box-sizing: border-box;
    .item {
      box-sizing: border-box;
      width: 710rpx;
      height: 320rpx;
      background: #fff;
      margin: 20rpx;
      padding: 20rpx;
      border-radius: 20rpx 20rpx 20rpx 20rpx;
      .top {
        display: flex;
        .topright {
          margin-left: 20rpx;
          .right {
            display: flex;
            .school {
              box-sizing: border-box;
              font-size: 22rpx;
              font-family: PingFang SC, PingFang SC;
              font-weight: 500;
              width: 172rpx;
              height: 40rpx;
              background: #eaedfd;
              border-radius: 10rpx 10rpx 10rpx 10rpx;
              color: #3553e8;
              text-align: center;
              line-height: 40rpx;
              text-overflow: ellipsis;
              white-space: nowrap;
              overflow: hidden;
            }
          }
        }
      }
      .bottom {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        margin-top: 30rpx;
        .checkbtn {
          box-sizing: border-box;
          width: 140rpx;
          height: 52rpx;
          text-align: center;
          line-height: 52rpx;
          background: #ffffff;
          border-radius: 100rpx 100rpx 100rpx 100rpx;
          color: #3553e8;
          font-size: 26rpx;
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
          border: 2rpx solid #3553e8;
          margin-right: 20rpx;
        }
        .savebtn {
          box-sizing: border-box;
          width: 140rpx;
          height: 52rpx;
          text-align: center;
          line-height: 52rpx;
          background: #3553e8;
          border-radius: 100rpx 100rpx 100rpx 100rpx;
          color: #fff;
          font-size: 26rpx;
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
        }
      }
    }
  }
}
</style>
<style>
page {
  background-color: #f9f9f9;
}
</style>
